ePaper (IL3820) module Library  v0.5
Library for the 2.9-inch WaveShare ePaper display module
libil3820.c
1 
2 
3 
4 
5 /*
6  * @file libil3820.c
7  *
8  * @author Matthew Matz & Roy Eltham
9  *
10  * @version 0.5
11  *
12  * @copyright Copyright (C) Parallax, Inc. 2018. See end of file for
13  * terms of use (MIT License).
14  *
15  * @brief Waveshare ePaper driver source, see il3820.h for documentation.
16  *
17  * @detail Please submit bug reports, suggestions, and improvements to
18  * this code to editor@parallax.com.
19  */
20 
21 
22 
23 
24 #include "il3820.h"
25 #include "simpletools.h"
26 
27 //#define TEST_IT_ALL
28 
29 screen *epd;
30 
31 
32 int main()
33 {
34 
35  //set up the ePaper screen
36  epd = il3820_init(0, 1, 2, 3, 4, 5, 128, 296);
37  fillRoundRect(epd, 30, 30, 30, 30, 5, 0);
38 
39  setDisplayRotation(epd, 1);
40  drawLine(epd, 0,0,50,0, 0);
41 
42  fillRect(epd, 20, 20, 60, 60, BLACK);
43 
44  drawRect(epd, 22, 22, 56, 56, INVERSE);
45 
46  fillCircle(epd, 50, 50, 20, WHITE);
47  drawCircle(epd, 50, 50, 18, BLACK);
48  fillCircle(epd, 50, 50, 16, BLACK);
49  drawCircle(epd, 50, 50, 14, WHITE);
50 
51  setCursor(epd, 10, 5, 0);
52 
53  drawPrint(epd, "Screen Testing 0123456789");
54 
55  setCursor(epd, 20, 90, 0);
56  setTextSize(epd, 2);
57 
58  drawPrint(epd, "Font Size Test");
59 
60  for (int t = 0; t < getDisplayHeight(epd); t+=10) {
61  //drawLine(epd, t, 0, getDisplayWidth(epd) - t, getDisplayHeight(epd), INVERSE);
62  //drawFastHLine(epd, 0, t, getDisplayWidth(epd), INVERSE);
63  }
64  for (int t = 0; t < getDisplayWidth(epd); t+=10) {
65  //drawLine(epd, t, 0, getDisplayWidth(epd) - t, getDisplayHeight(epd), INVERSE);
66  //drawFastVLine(epd, t, 0, getDisplayHeight(epd), INVERSE);
67  }
68 
69  updateDisplay(epd);
70 
71 #ifdef TEST_IT_ALL
72 
73  pause(2000);
74 
75  clearDisplay(epd);
76 
77  setDisplayRotation(epd, 0);
78 
79  for (int i = 1; i < 4; i++)
80  {
81  for (int r = 0; r < 4; r++)
82  {
83  for (int o = 0; o < getDisplayWidth(epd); o += 10) drawFastVLine(epd, o, 0, getDisplayHeight(epd), BLACK);
84  for (int o = 0; o < getDisplayHeight(epd); o += 20) drawFastHLine(epd, 0, o, getDisplayWidth(epd), BLACK);
85 
86  setTextSize(epd, i);
87  setTextFont(epd, r);
88  setCursor(epd, 0, 0, 0);
89 
90  drawNumber(epd, 28, DEC);
91  drawText(epd, " | ");
92  drawNumber(epd, -28, DEC);
93  drawText(epd, "\n");
94  drawNumber(epd, -28, HEX);
95  drawText(epd, " | ");
96  drawNumber(epd, 28, BIN);
97  drawNumber(epd, 28, OCT);
98  drawText(epd, " | ");
99  drawNumber(epd, -36.93715, 2);
100  drawText(epd, "\n");
101  for (int xy = 'A'; xy <= 'Z'; xy++)
102  {
103  drawChar(epd, xy);
104  }
105  updateDisplay(epd);
106  pause(500);
107 
108  clearDisplay(epd);
109 
110  // small size only has one font, so skip
111  if (i == 1) r = 4;
112  }
113  }
114 
115 
116 
117 low(27);
118  for(int r = 0; r < 4; r++)
119  {
120  il3820_setRotation(r);
121 
122  for(int o=0; o<il3820_getWidth(); o+=10) il3820_drawFastVLine(o, 0, il3820_getHeight(), BLACK);
123  for(int o=0; o<il3820_getHeight(); o+=20) il3820_drawFastHLine(0, o, il3820_getWidth(), BLACK);
124 
125  for(int df = -20; df < 120; df += 10) il3820_drawLine(df, 40, 40, 120 - df, BLACK);
126  il3820_updateDisplay();
127  //pause(500);
128 
129  il3820_clear(0,0,il3820_getWidth(),il3820_getHeight());
130  }
131 
133  /*
134  for(int r = 0; r < 4; r++)
135  {
136  il3820_setRotation(r);
137 
138  for(int o=0; o<il3820_getWidth(); o+=10) il3820_drawFastVLine(o, 0, il3820_getHeight(), BLACK);
139  for(int o=0; o<il3820_getHeight(); o+=20) il3820_drawFastHLine(0, o, il3820_getWidth(), BLACK);
140 
141  il3820_drawPixel(1, 1, WHITE);
142 
143  il3820_drawPixel(20,20, WHITE);
144 
145  il3820_drawPixel(30, 10, WHITE);
146 
147  il3820_drawPixel(45, 50, BLACK);
148  il3820_drawPixel(10, 45, BLACK);
149  il3820_drawPixel(45, 45, BLACK);
150  il3820_drawPixel(35, 45, BLACK);
151 
152  il3820_updateDisplay();
153  pause(500);
154 
155  il3820_clear(0,0,il3820_getWidth(),il3820_getHeight());
156  }
157 */
159 
160 
162 
163  for(int r = 0; r < 4; r++)
164  {
165  il3820_setRotation(r);
166 
167  for(int o=0; o<il3820_getWidth(); o+=10) il3820_drawFastVLine(o, 0, il3820_getHeight(), BLACK);
168  for(int o=0; o<il3820_getHeight(); o+=20) il3820_drawFastHLine(0, o, il3820_getWidth(), BLACK);
169 
170 
171  il3820_drawLine(1, 1, 20,20, WHITE);
172 
173  il3820_drawLine(20, 20, 30, 10, WHITE);
174 
175  il3820_drawLine(30, 10, 45, 80, BLACK);
176  il3820_drawLine(45, 80, 125, 30, BLACK);
177  il3820_drawLine(125, 30, 45, -5, BLACK);
178  il3820_drawLine(45, -5, -10, 20, BLACK);
179 
180  il3820_updateDisplay();
181  //pause(500);
182 
183  il3820_clear(0,0,il3820_getWidth(),il3820_getHeight());
184  }
185 
187 
189 
190  for(int r = 0; r < 4; r++)
191  {
192  il3820_setRotation(r);
193 
194  for(int o=0; o<il3820_getWidth(); o+=10) il3820_drawFastVLine(o, 0, il3820_getHeight(), BLACK);
195  for(int o=0; o<il3820_getHeight(); o+=20) il3820_drawFastHLine(0, o, il3820_getWidth(), BLACK);
196 
197  il3820_drawCircle(10, 10, 5, BLACK);pause(5);
198  il3820_drawCircle(15, 20, 10, BLACK);pause(5);
199  il3820_drawCircle(20, 30, 15, BLACK);pause(5);
200  il3820_drawCircle(25, 40, 20, BLACK);pause(5);
201  il3820_drawCircle(30, 50, 25, BLACK);pause(5);
202  il3820_updateDisplay();
203  //pause(500);
204 
205  il3820_clear(0,0,il3820_getWidth(),il3820_getHeight());
206  }
207 
209 
211 
212  for(int r = 0; r < 4; r++)
213  {
214  il3820_setRotation(r);
215 
216  for(int o=0; o<il3820_getWidth(); o+=10) il3820_drawFastVLine(o, 0, il3820_getHeight(), BLACK);
217  for(int o=0; o<il3820_getHeight(); o+=20) il3820_drawFastHLine(0, o, il3820_getWidth(), BLACK);
218 
219 
220  il3820_fillCircle(10, 10, 5, BLACK); pause(5);
221  il3820_fillCircle(15, 20, 10, BLACK);pause(5);
222  il3820_fillCircle(20, 30, 15, BLACK);pause(5);
223  il3820_fillCircle(25, 40, 20, BLACK);pause(5);
224  il3820_fillCircle(30, 50, 25, BLACK);pause(5);
225  il3820_updateDisplay();
226  //pause(500);
227 
228  il3820_clear(0,0,il3820_getWidth(),il3820_getHeight());
229  }
230 
232 
233  for(int r = 0; r < 4; r++)
234  {
235  il3820_setRotation(r);
236 
237  for(int o=0; o<il3820_getWidth(); o+=10) il3820_drawFastVLine(o, 0, il3820_getHeight(), BLACK);
238  for(int o=0; o<il3820_getHeight(); o+=20) il3820_drawFastHLine(0, o, il3820_getWidth(), BLACK);
239 
240  il3820_fillRect(10, 10, 5, 5, BLACK);
241  il3820_fillRect(15, 20, 10, 10, BLACK);
242  il3820_fillRect(20, 30, 15, 20, BLACK);
243  il3820_fillRect(25, 40, 20, 30, BLACK);
244  il3820_fillRect(30, 50, 25, 40, BLACK);
245  il3820_updateDisplay();
246  //pause(500);
247 
248  il3820_clear(0,0,il3820_getWidth(),il3820_getHeight());
249  }
250 
251  for(int r = 0; r < 4; r++)
252  {
253  il3820_setRotation(r);
254 
255  for(int o=0; o<il3820_getWidth(); o+=10) il3820_drawFastVLine(o, 0, il3820_getHeight(), BLACK);
256  for(int o=0; o<il3820_getHeight(); o+=20) il3820_drawFastHLine(0, o, il3820_getWidth(), BLACK);
257 
258  il3820_fillRoundRect(10, 10, 5, 5, 5, BLACK);
259  il3820_fillRoundRect(15, 20, 10, 10, 5, BLACK);
260  il3820_fillRoundRect(20, 30, 15, 20, 5, BLACK);
261  il3820_fillRoundRect(25, 40, 20, 30, 5, BLACK);
262  il3820_fillRoundRect(30, 50, 25, 40, 5, BLACK);
263  il3820_updateDisplay();
264  //pause(500);
265 
266  il3820_clear(0, 0, il3820_getWidth(), il3820_getHeight());
267  }
268 
269  il3820_sleep();
270  pause(2000);
271  il3820_wake();
272 
273  il3820_setRotation(0);
274  il3820_setTextSize(1);
275  il3820_setTextFont(1);
276  il3820_setCursor(0, 0, 0);
277  il3820_drawText("Done.\n");
278  il3820_updateDisplay();
279  low(26); low(27);
280 
282 
283 #endif // TEST_IT_ALL
284 
285 }
286 
287